const jwt = require('jsonwebtoken');
const { tokenKey } = require('../config')
/**
 * 生成token
 * @param payload
 * @returns {*}
 */
function generateToken(payload) {
	return jwt.sign({
		data: payload
	}, tokenKey, {
		expiresIn: '1d'
	});
}

/**
 * 验证token
 * @param token
 * @returns {*}
 */
function verifyToken(token) {
	return jwt.verify(token, tokenKey);
}

module.exports = {
	generateToken,
	verifyToken,
}